package com.example.tacocloud.mapper;

import com.example.tacocloud.bean.Order;
import com.example.tacocloud.bean.Taco;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderMapper {

    @Insert("insert into Taco_Order (deliveryName, deliveryStreet, deliveryCity, deliveryState, deliveryZip, ccNumber," +
            "ccExpiration, ccCVV, placedAt, uid) values (#{deliveryName}, #{deliveryStreet}, #{deliveryCity}, #{deliveryState}, " +
            "#{deliveryZip}, #{ccNumber}, #{ccExpiration}, #{ccCVV}, #{placedAt}, #{uid})")
    public long saveOrderDetails(Order order);

    @Insert("insert into Taco_Order_Tacos (tacoOrder, taco) values (#{orderId}, #{tacoId})")
    public void saveTacoToOrder(long orderId, long tacoId);

    @Select("select id from Taco_Order where deliveryName=#{deliveryName}")
    public long findOrderId(String deliveryName);

    @Select("select * from Taco_Order where uid = #{uid} order by placedAt DESC limit 0, #{offset}")
    List<Order> findOrdersByUserId(long uid, int offset);
}
